package com.fa.production.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.fa.production.domain.*;
import com.fa.production.mapper.ProcessMapper;
import com.fa.production.service.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProcessServiceImpl implements ProcessService {
    @Autowired
    private ProcessMapper processMapper;
    @Override
    public List<Processs> getlist(Processs process) {
        return processMapper.getlist(process);
    }

    @Override
    public Processs selectProcesssById(Integer routeId) {
        return processMapper.selectProcesssById(routeId);
    }

    @Override
    public int insertProcesss(Processs process) {
        return processMapper.insertProcesss(process);
    }

    @Override
    public int deleteProcesssById(List<Integer> routeId) {
        return processMapper.deleteProcesssById(routeId);
    }

    @Override
    public int updateProcesss(Processs process) {
        return processMapper.updateProcesss(process);
    }

    @Override
    public List<ProRouteProduct> getlist2(Integer routeId) {
        return processMapper.getlist2(routeId);
    }

    @Override
    public List<ProRouteProcess> getlist1(Long routeId) {
        return processMapper.getlist1(routeId);
    }

    @Override
    public int insertRouteProcesss(ProRouteProcess proRouteProcess) {
        return processMapper.insertRouteProcesss(proRouteProcess);
    }

    @Override
    public int deleteRouteProcesssById(List<Integer> recordId) {
        return processMapper.deleteRouteProcesssById(recordId);
    }

    @Override
    public ProRouteProcess selectRouteProcessById(Integer recordId) {
        return processMapper.selectrouteProcesssById(recordId);
    }

    @Override
    public int updateRouteProcesss(ProRouteProcess proRouteProcess) {
        return processMapper.updateRouteProcesss(proRouteProcess);
    }

    @Override
    public List<Tree<String>> getMdItemTypeTreeList() {
        // 查询全部数据
        List<MdItemType> nodeList = processMapper.selectAllItem();

        //配置
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        // 自定义属性名 都有默认值的
        //treeNodeConfig.setWeightKey("quantity");
        treeNodeConfig.setIdKey("itemTypeId");

        List<Tree<String>> treeNodes = TreeUtil.build(nodeList, "0", treeNodeConfig,
                (treeNode, tree) -> {
                    tree.setId(treeNode.getItemTypeId().toString());
                    tree.setParentId(treeNode.getParentTypeId().toString());
                    //tree.setWeight(treeNode.getQuantity());
                    // 扩展属性 ...
                    tree.putExtra("itemTypeName", treeNode.getItemTypeName());
                });
        return treeNodes;
    }

    @Override
    public List<MdItem> getMdItemList(MdItem mdItem) {
        System.out.println(processMapper.getMdItemList(mdItem));
        return processMapper.getMdItemList(mdItem);
    }

    @Override
    public ArrayList<MdItem> getMdItemByIdList(ArrayList<Long> allIds) {
        System.out.println(allIds);
        return processMapper.getMdItemByIdList(allIds);
    }

    @Override
    public int insertRouteProduct(ProRouteProduct proRouteProduct) {
        return processMapper.insertRouteProduct(proRouteProduct);
    }

    @Override
    public ProRouteProduct selectRouteProductById(Integer recordId) {
        return processMapper.selectRouteProductById(recordId);
    }

    @Override
    public int updateRouteProduct(ProRouteProduct proRouteProduct) {
        return processMapper.updateRouteProduct(proRouteProduct);
    }

    @Override
    public int deleteRouteProductById(List<Integer> recordId) {
        return processMapper.deleteRouteProductById(recordId);
    }
}
